#******************************************************************
#
# Copyright 2015 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

##
# ResourceCache Unit Test build script
##
# SConscript file for Local PKI google tests
from tools.scons.RunTest import run_test

gtest_env = SConscript('#extlibs/gtest/SConscript')
lib_env = gtest_env.Clone()

if lib_env.get('RELEASE'):
    lib_env.AppendUnique(CCFLAGS=['-Os'])
else:
    lib_env.AppendUnique(CCFLAGS=['-g'])

SConscript('#service/third_party_libs.scons', 'lib_env')

######################################################################
# unit test setting
######################################################################
cache_test_env = lib_env.Clone()
target_os = cache_test_env.get('TARGET_OS')

######################################################################
# Build flags
######################################################################

cache_test_env.AppendUnique(CPPPATH=[
    '../include',
    '../../../include',
    '../../common/primitiveResource/include',
    '../../common/expiryTimer/include',
    '../../common/expiryTimer/src',
    '../../common/utils/include',
    '#/resource/c_common',
    '#/resource/c_common/oic_malloc/include',
    '#/resource/c_common/oic_string/include',
    '#/resource/csdk/include',
    '#/resource/csdk/stack/include',
    '#/resource/include',
    '#/resource/oc_logger/include'
])
cache_test_env.PrependUnique(CPPPATH=['#/extlibs/hippomocks/hippomocks'])
cache_test_env.PrependUnique(LIBS=[
    'rcs_client',
    'rcs_common',
    'oc',
    'octbstack',
    'oc_logger',
    'connectivity_abstraction',
    'coap',
])

compiler = cache_test_env.get('CXX')
if 'g++' in compiler:
    cache_test_env.AppendUnique(
        CXXFLAGS=['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])

if cache_test_env.get('SECURED') == '1':
    cache_test_env.AppendUnique(LIBS=['mbedtls', 'mbedx509', 'mbedcrypto'])

######################################################################
# Build Test
######################################################################
cache_test_src = cache_test_env.Glob('./*.cpp')
cache_test = cache_test_env.Program('cache_test', cache_test_src)
Alias("cache_test", cache_test)
cache_test_env.AppendTarget('cache_test')
cache_test_env.UserInstallTargetExtra(cache_test,'tests/service/resource-encapsulation/src/resourceCache/')

if cache_test_env.get('TEST') == '1':
    if target_os in ['linux']:
        run_test(
            cache_test_env,
            'service_resource-encapsulation_src_resourceCache_unittests_cache_test.memcheck',
            'service/resource-encapsulation/src/resourceCache/unittests/cache_test',
            cache_test)
